package com.fwtai.api.controller;

import com.fwtai.config.ConfigFile;
import com.fwtai.service.api.ApiCartsService;
import com.fwtai.tool.ToolClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 购物车
 * @作者 田应平
 * @版本 v1.0
 * @创建时间 2023-09-25 14:51:14
 * @QQ号码 444141300
 * @Email service@fwtai.com
 * @官网 <url>http://www.fwtai.com</url>
*/
@Api(tags = "购物车,token必填",description = "用户的购物车,token必填")
@RestController
@RequestMapping(ConfigFile.guest_v10 + "carts")
public class CartsController{

  private final ApiCartsService apiCartsService;

  public CartsController(final ApiCartsService apiCartsService){
    this.apiCartsService = apiCartsService;
  }

  @ApiOperation(value = "获取我的已购买的默认门店的信息,token必填", notes = "获取我的已购买的默认门店的信息")
  @GetMapping("/getStoreId")
  void getStoreId(final HttpServletResponse response){
    ToolClient.responseJson(apiCartsService.getStoreId(),response);
  }

  @ApiOperation(value = "加入购物车,token必填", notes = "加入购物车")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "kid", value = "门店商品库存id", dataType = "String", paramType = "query",required = true),
    @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query",required = true),
    @ApiImplicitParam(name = "total", value = "商品数量", dataType = "int", paramType = "query",required = true)
  })
  @PostMapping("/addCarts")
  public void addCarts(final String kid,final String storeId,final String total,final HttpServletResponse response){
    ToolClient.responseJson(apiCartsService.addCarts(kid,storeId,total),response);
  }

  //编辑购物车的商品的数量,当为时提示是否要删除该商品
  @ApiOperation(value = "编辑购物车的商品的数量,token必填", notes = "编辑购物车的商品的数量,当减少为0时小程序端可提示是否要删除该商品")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "kid", value = "购物车的kid", dataType = "String", paramType = "query",required = true),
    @ApiImplicitParam(name = "total", value = "商品数量", dataType = "int", paramType = "query",required = true)
  })
  @PostMapping("/editCarts")
  public void editCarts(final String kid,final String total,final HttpServletResponse response){
    ToolClient.responseJson(apiCartsService.editCarts(kid,total),response);
  }

  @ApiOperation(value = "编辑购物车的商品的数量,token必填", notes = "删除单个或批量购物车的商品|清空删除全部购物车的商品")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "ids", value = "购物车的kid集合,单个时则删除单个,多个时则是批量删除商品,格式:4415xxx,79968xxx,256510279686441517", dataType = "String", paramType = "query",required = false),
    @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query",required = false),
    @ApiImplicitParam(name = "type", value = "是否清空删除全部购物车的商品(1时是全部删除清空购物车商品,0则按照参数`ids`来删除对应的商品)", dataType = "int", paramType = "query",required = true)
  })
  @PostMapping("/delCarts")
  public void delCarts(final String ids,final String storeId,final String type,final HttpServletResponse response){
    ToolClient.responseJson(apiCartsService.delCarts(type,storeId,ids),response);
  }

  /**获取分页数据,请勿删除ReqPage否则swagger不显示参数*/
  @ApiOperation(value = "获取购物车分页数据(目前暂时不分页),默认仅含数据不含总记录数总条数,token必填", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求")
  @GetMapping("/listCarts")
  public void listCarts(final Long storeId,final HttpServletResponse response){
    ToolClient.responseJson(apiCartsService.listCarts(storeId),response);
  }

  @ApiOperation(value = "查看我的购物车的商品种类数量,token必填", notes = "查看我的购物车的商品种类数量,token必填")
  @GetMapping("/getCartsTotal")
  public void getCartsTotal(final HttpServletResponse response){
    ToolClient.responseJson(apiCartsService.getCartsTotal(),response);
  }

  //根据门店id和商品的id，查询门店库存商品kid
  @ApiOperation(value = "根据门店id和商品的id，查询门店库存商品kid,token必填", notes = "根据门店id和商品的id，查询门店库存商品kid,token必填")
  @GetMapping("/queryStoreGoods")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "storeId", value = "门店kid", dataType = "String", paramType = "query",required = false),
    @ApiImplicitParam(name = "goodsId", value = "门店商品库存id", dataType = "int", paramType = "query",required = true)
  })
  public void queryStoreGoods(final String storeId,final String goodsId,final HttpServletResponse response){
    ToolClient.responseJson(apiCartsService.queryStoreGoods(storeId,goodsId),response);
  }
}